// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: jingyan

#include <string>

#include "coin2/base/config/app_config.h"
#include "coin2/base/config/args.h"
#include "coin2/base/log.h"
#include "ctime"
#include "experimental/jingyuan/basis_exchange_strategy.h"
#include "presto/quant/feature/feature.h"

using namespace ::coin2::exchange::base::symbology;
using namespace ::coin2::base::config;
using namespace ::coin2::exchange::feed;
using namespace ::coin2::app;

namespace {

void AddSimulationOptions(cxxopts::Options* opt) {
  opt->add_options()("latency_sec", "", cxxopts::value<std::string>());
  opt->add_options()("sim_result_filepath", "", cxxopts::value<std::string>());
}

}  // namespace

int main(int argc, char* argv[]) {
  InitModules();  // init for

  DriverConfig app;

  cxxopts::Options opt("btc huobi oken basis", "lm-agg Live Pilot");
  opt.add_options()("basis_strat_json", "config json path", cxxopts::value<std::string>());
  opt.add_options()("dryrun", "if dryrun, enable OE && disable OG", cxxopts::value<bool>());
  AddDriverOptions(&opt);
  AddIntervalOptions(&opt);
  AddProductOptions(&opt);
  AddSimulationOptions(&opt);
  AddFeedArchiveOptions(&opt);

  auto res = opt.parse(argc, argv);
  ParseDriverOptions(res, &app);
  LOG(INFO) << app.DebugString();
  ParseIntervalOptions(
      res,
      app.mutable_feed()->mutable_common()->mutable_archive()->mutable_interval());
  ParseProductOptions(res, app.mutable_feed());

  LOG(INFO) << app.DebugString();

  auto* mut_sim_config = app.mutable_order()->mutable_common()->mutable_sim_config();
  mut_sim_config->set_result_format(
      coin2::exchange::order::SimConfig::RESULT_FORMAT_PROTO_FILE_DUMP);
  mut_sim_config->set_sim_result_filepath(res["sim_result_filepath"].as<std::string>());

  ::coin2::base::InitLogging(argv[0], app.log());

  auto begin_end = GetEnclosingInterval(app);

  coin2::strategy::basis_strategy::BasisStrategy stg(
      res["basis_strat_json"].as<std::string>(),
      begin_end.first);
  Driver driver(app, &stg);
  driver.RegisterCleanupHandler();
  driver.Run();

  return 0;
}
